<?php

/**
 * Framework_Presenter_REST
 *
 * @author Application Support Group
 * @copyright University of Georgia
 * @package BAMF
 * @filesource
 */

require_once('XML/Serializer.php');

/**
 * Framework_Presenter_REST
 *
 * Want to display your module's data in valid XML rather than HTML? This
 * presenter will automatically take your data and output it in valid XML.
 *
 * @author Application Support Group
 * @package BAMF
 */
class Framework_Presenter_REST extends Framework_Presenter_Common
{
    /**
     * __construct
     *
     * @author Application Support Group
     * @access public
     * @param mixed $module Instance of Framework_Module
     * @return void
     */
    public function __construct(Framework_Module $module)
    {
        parent::__construct($module);
    }

    /**
     * display
     *
     * Output our data array using the PEAR package XML_Serializer. This may
     * not be the optimal output you want for your REST API, but it should
     * display valid XML that can be easily consumed by anyone. Note that if you
	 * have an array with integer keys, the numeric values will be lost and turned
     * into generic "XML_Serializer_Tag" tags.
     *
     * @author Application Support Group
     * @return void
     * @link http://pear.php.net/package/XML_Serializer
     */
    public function display()
    {
        $xml = new XML_Serializer();
        $xml->serialize($this->module->getData());

        header("Content-Type: text/xml");
        echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
        echo $xml->getSerializedData();
    }

    public function __destruct()
    {
        parent::__destruct();
    }
}

?>
